package com.example.demo.controller;

import com.example.demo.pojo.Helldevice;
import com.example.demo.pojo.PageResult;
import com.example.demo.pojo.Result;
import com.example.demo.service.Impl.HelldeviceServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class HelldeviceController {
    @Autowired
    private HelldeviceServiceImpl helldeviceService;
    //地府设备查询
    @GetMapping("/helllist")
    public Result HelldeviceQuery(@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer limit,
                             Integer floor){
        PageInfo list = helldeviceService.HelldeviceQuery(page,limit,floor);
        return PageResult.success03(list.getList(), (int) list.getTotal());
    }
    //地府设备添加
    @PostMapping("/helladd")
    public Result HelldeviceAdd(@RequestBody Helldevice helldevice){
        helldeviceService.HelldeviceAdd(helldevice);
        return Result.success("添加成功");
    }
    //地府设备修改
    @PutMapping("/hellupdate")
    public Result HelldeviceUpdate(@RequestBody Helldevice helldevice){
        helldeviceService.HelldeviceUpdate(helldevice);
        return Result.success("修改成功");
    }
    //地府设备开启或关闭
    @PutMapping("/hellstatus")
    public Result HelldeviceUpdateStatus(@RequestBody Helldevice helldevice){
        helldeviceService.HelldeviceUpdateStatus(helldevice);
        return Result.success("修改成功");
    }
    //地府设备删除
    @DeleteMapping("/helldel")
    public Result HelldeviceDelete(Integer id){
        helldeviceService.HelldeviceDelete(id);
        return Result.success("删除成功");
    }
}
